package com.wendy.admin.api.factory;

import com.wendy.admin.api.RemoteUserService;
import com.wendy.admin.api.domain.LoginSysUser;
import com.wendy.admin.api.model.LoginUser;
import com.wendy.common.core.errcode.user.UserError;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 用户服务降级处理
 * 
 * @author wendy
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteUserService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteUserService()
        {
            @Override
            public LoginUser getUserInfo(String username)
            {
                UserError.GET_USER_FAIL.formatFire(throwable.getMessage());
                return null;

            }

            @Override
            public Boolean registerUserInfo(LoginSysUser sysUser)
            {
                UserError.REGISTER_USER_FAIL.formatFire(throwable.getMessage());
                return false;
            }
        };
    }
}
